﻿// See https://aka.ms/new-console-template for more information
using MySql.Data.MySqlClient;
//使用前请先执行 init.sql, 用户信息: 
//user geraltigas
//passwd 1234
namespace Test
{
    public class Utils
    {
        public static void Main(string[] args)
        {

        }
        public static MySqlConnection connect()
        {
            MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
            builder.UserID = "geraltigas";
            builder.Password = "1234";
            builder.Server = "localhost";
            builder.Database = "geraltigas";
            var conn = new MySqlConnection(builder.ConnectionString);
            conn.Open();
            return conn;
        }

        public static int getMaxID(MySqlConnection conn)
        {
            MySqlCommand command = new MySqlCommand();
            command.Connection = conn;
            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = "use geraltigas;select MAX(vacabulary_id) from geraltigas.vacabulary;";
            var obj = command.ExecuteScalar();
            return (Int32)obj;
        }

        public static LinkedList<string> getPair(int index, MySqlConnection conn)
        {
            MySqlCommand command = new MySqlCommand();
            command.Connection = conn;
            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = string.Format("use geraltigas;select * from geraltigas.vacabulary where vacabulary_id = {0};", index);
            var obj = command.ExecuteReader();
            Console.WriteLine(obj);
            var temp = new LinkedList<string>();
            obj.Read();
            temp.AddLast(obj["chinese"].ToString());
            temp.AddLast(obj["english"].ToString());
            obj.Close();

            return temp;
        }
    }
    
}


